﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace NJL.WebManage.SystemAdmin
{
    public partial class WebSiteContact : BasePage
    {
        NJL.BLL.NJL_SYS_CONTACT bllContact = new BLL.NJL_SYS_CONTACT();
        NJL.Model.NJL_SYS_CONTACT modelContact;
        NJL.BLL.NJL_SYS_CS_CONTACT_TYPE bllType = new BLL.NJL_SYS_CS_CONTACT_TYPE();
        NJL.Model.NJL_SYS_CS_CONTACT_TYPE modelType;
        DataSet ds;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ds = bllContact.GetList("NJL_SYS_BASE_ID='" + Request.QueryString["id"] + "' and TYPE_CODE='" + Request.QueryString["typeId"] + "'");
                modelType = bllType.GetModel(Request.QueryString["typeId"]);
                ltlType.Text = modelType.TYPE_NAME;
                DataRow dr = ds.Tables[0].Rows[0];
                txtContactPerson.Text = dr["WEBSITE_CONTACT"].ToString();
                txtContactTel.Text = dr["WEBSITE_CONTACT_TEL"].ToString();
                txtContactFax.Text = dr["WEBSITE_CONTACT_FAX"].ToString();
                txtContactMobel.Text = dr["WEBSITE_CONTACT_MOBILE"].ToString();
                txtContactQQ.Text = dr["WEBSITE_CONTACT_QQ"].ToString();
                txtContactMsn.Text = dr["WEBSITE_CONTACT_MSN"].ToString();
                txtContactEmail.Text = dr["WEBSITE_CONTACT_EMAIL"].ToString();
                txtContactPost.Text = dr["WEBSITE_CONTACT_POST"].ToString();
                txtContactAddress.Text = dr["WEBSITE_CONTACT_ADDRESS"].ToString();
                txtContactDesc.Text = dr["WEBSITE_CONTACT_INTRO"].ToString();
            }

        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            ds = bllContact.GetList("NJL_SYS_BASE_ID='" + Request.QueryString["id"] + "' and TYPE_CODE='" + Request.QueryString["typeId"] + "'");
            if (ds.Tables[0].Rows.Count > 0)
            {
                modelContact = bllContact.GetModel(ds.Tables[0].Rows[0][0].ToString());
                modelContact.WEBSITE_CONTACT = txtContactPerson.Text.Trim();
                modelContact.WEBSITE_CONTACT_TEL = txtContactTel.Text.Trim();
                modelContact.WEBSITE_CONTACT_FAX = txtContactFax.Text.Trim();
                modelContact.WEBSITE_CONTACT_MOBILE = txtContactMobel.Text.Trim();
                modelContact.WEBSITE_CONTACT_QQ = txtContactQQ.Text.Trim();
                modelContact.WEBSITE_CONTACT_MSN = txtContactMsn.Text.Trim();
                modelContact.WEBSITE_CONTACT_EMAIL = txtContactEmail.Text.Trim();
                modelContact.WEBSITE_CONTACT_POST = txtContactPost.Text.Trim();
                modelContact.WEBSITE_CONTACT_ADDRESS = txtContactAddress.Text.Trim();
                modelContact.WEBSITE_CONTACT_INTRO = txtContactDesc.Text.Trim();
                modelContact.UPDATE_DATE_TIME = DateTime.Now;
                modelContact.UPDATE_USER_ID = USER_ID;
                modelContact.UPDATE_USER_NAME = USER_NAME;
                if (bllContact.Update(modelContact))
                {
                    Royalsoft.Common.MessageBox.ShowAndRedirect(this, "更新成功", Request.RawUrl);
                }
            }
        }
    }
}